package com.andy.basics;

import java.util.Date;

public abstract class AbstractEntity implements com.andy.basics.Entity, Comparable<Entity> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2436108296953445662L;

	private boolean selected;

	/**
	 * Date on which this entity was created
	 */
	protected Date date = new Date();

	protected int id;

	public void setSelected(final boolean selected) {
		this.selected = selected;
	}

	public boolean isSelected() {
		return this.selected;
	}

	public void setId(final int id) {
		this.id = id;
	}

	public void setDate(final Date date) {
		this.date = date;
	}

	public Date getDate() {
		// TODO Auto-generated method stub
		return this.date;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		// Never refer the field directly, use getter !
		result = prime * result + this.getId();
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (this.getClass() != obj.getClass()) {
			return false;
		}
		AbstractEntity other = (AbstractEntity) obj;
		if (this.getId() != other.getId()) {
			return false;
		}
		return true;
	}

	public int compareTo(Entity o) {
		return this.getId() - o.getId();
	}
}
